package com.momo.rabbitsingleproducer.controller;

import com.momo.rabbitsingleproducer.entity.JSONResult;
import com.momo.rabbitsingleproducer.entity.SysUser;
import com.momo.rabbitsingleproducer.rabbitmq.dead.TopicOrderDeadSingelRabbitSender;
import com.momo.rabbitsingleproducer.rabbitmq.direct.DirectSingelRabbitSender;
import com.momo.rabbitsingleproducer.rabbitmq.fanout.FanoutSingelRabbitSender;
import com.momo.rabbitsingleproducer.rabbitmq.topic.TopicSingelRabbitSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @program: momo-cloud
 * @description: rabbitMQ rest发送消息
 * @author: Jie Li
 * @create: 2019-07-27 15:22
 **/
@RestController
@RequestMapping(value = "/platform/rabbitmq", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@Slf4j
public class RabbitMqController {
    @Autowired
    private TopicSingelRabbitSender singelRabbitSender_topic;
    @Autowired
    private FanoutSingelRabbitSender fanoutSingelRabbitSender;
    @Autowired
    private DirectSingelRabbitSender directSingelRabbitSender;
    @Autowired
    private TopicOrderDeadSingelRabbitSender topicOrderDeadSingelRabbitSender;
    /**
     * Topic 主题
     *
     * @return
     */
    @RequestMapping("/topicSender/v1")
    public JSONResult topicSender() {
        SysUser sysUser = new SysUser();
        sysUser.setId(1L);
        sysUser.setSysUserName("李杰");
        sysUser.setCreateTime(new Date());
        singelRabbitSender_topic.send(JSONResult.ok(sysUser), null);
        return JSONResult.ok("RabbitMQ Topic 主题消息发送成功");
    }

    /**
     * Fanout 主题
     *
     * @return
     */
    @RequestMapping("/fanoutSender/v1")
    public JSONResult fanoutSender() {
        SysUser sysUser = new SysUser();
        sysUser.setId(1L);
        sysUser.setSysUserName("李杰");
        sysUser.setCreateTime(new Date());
        fanoutSingelRabbitSender.send(JSONResult.ok(sysUser), null);
        return JSONResult.ok("RabbitMQ Fanout 主题消息发送成功");
    }

    /**
     * Direct 主题
     *
     * @return
     */
    @RequestMapping("/directSender/v1")
    public JSONResult directSender() {
        SysUser sysUser = new SysUser();
        sysUser.setId(1L);
        sysUser.setSysUserName("李杰");
        sysUser.setCreateTime(new Date());
        directSingelRabbitSender.send(JSONResult.ok(sysUser), null);
        return JSONResult.ok("RabbitMQ Direct 主题消息发送成功");
    }

    /**
     * 死信队列
     *
     * @return
     */
    @RequestMapping("/topicDeadSender/v1")
    public JSONResult topicDeadSender() {
        SysUser sysUser = new SysUser();
        sysUser.setId(1L);
        sysUser.setSysUserName("李杰");
        sysUser.setCreateTime(new Date());
        topicOrderDeadSingelRabbitSender.send(JSONResult.ok(sysUser), null);
        return JSONResult.ok("RabbitMQ Direct 主题消息发送成功");
    }

}
